package com.bnzj.cloud.business.core.persistence.entity;

import com.bnzj.core.persistence.entity.BaseEntity;
import com.fasterxml.jackson.annotation.JsonManagedReference;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import javax.persistence.*;
import javax.validation.constraints.NotNull;
import java.util.List;
import java.util.Set;

@Getter
@Setter
@ToString(exclude = {"roleResourceList", "roleUserList"}, callSuper = true)
@Entity
@Table(name = "bnz_sys_role")
@Schema(description = "角色")
public class SysRole extends BaseEntity {
    private static final long serialVersionUID = -1867411475978990633L;
    @Schema(description = "名称")
    @NotNull(message = "角色名称不能为空！")
    private String name;

    @Schema(description = "编码")
    @NotNull(message = "角色编码不能为空！")
    private String code;

    @Schema(description = "备注")
    private String remark;

    @Schema(description = "启用状态")
    private Boolean enabled = true;

    // mappedBy，映射SysRoleResource类里面的字段
    @OneToMany(mappedBy = "roleId", cascade = {CascadeType.ALL}, fetch = FetchType.EAGER)
    @JsonManagedReference(value = "relation-role-resource")
    private Set<SysRoleResource> roleResourceList;

    @OneToMany(mappedBy = "roleId", cascade = {CascadeType.ALL}, fetch = FetchType.LAZY)
    @JsonManagedReference(value = "relation-role-user")
    private List<SysRoleUser> roleUserList;
}
